﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.IO;

namespace teatimer
{
    static class Program
    {
        /// <summary>
        /// Der Haupteinstiegspunkt für die Anwendung.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            //Application.Run(new Form1()); // ohne Mutex

            if (!File.Exists("data.csv"))
            {
                File.WriteAllText("data.csv", "was,zeit,aufrufe\r\nPizza,20,0\r\nBaguette,10,0\r\nTee,5,0");
            }

            if (!System.IO.File.Exists("teatimer.ini"))
            {
                StreamWriter writer = new StreamWriter("teatimer.ini");
                writer.WriteLine("[Modes]");
                writer.WriteLine("lamer=0");
                writer.WriteLine("nice=0");
                writer.WriteLine("heavy=1");
                writer.WriteLine("update=0");
                writer.WriteLine("[Layout]");
                writer.WriteLine("Transparenz=60");
                writer.WriteLine("forecolor=Red");
                writer.WriteLine("backcolor=Yellow");
                writer.Close();
            }

            #region Form1 mit Mutex aufrufen
            bool createdNew;

            System.Threading.Mutex mutex = new System.Threading.Mutex(true, Application.ProductName, out createdNew);
            if (createdNew)
            {
                Application.Run(new Form1());
                mutex.ReleaseMutex();
            }
            else
            {
                MessageBox.Show("teatimer wurde bereits gestartet!", "teatimer-Info", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            #endregion
        }
    }
}